﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Alicanto.Helpers
{
    internal class Boxing
    {
        static internal Expression EnsureUnbox(Expression expression, Type to)
        {
            if (expression.Type == typeof(object))
            {
                expression = Expression.Convert(
                    expression,
                    to
                );
            }

            return expression;
        }

        static internal Expression EnsureBox(Expression expression, Type to)
        {
            if (expression.Type != to)
            {
                expression = Expression.Convert(
                    expression,
                    to
                );
            }

            return expression;
        }
    }
}
